package com.compass.mobile.presenters

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.leanback.widget.Presenter
import com.compass.mobile.R
import com.compass.mobile.framework.ext.gone
import com.compass.mobile.framework.ext.visible
import com.compass.mobile.framework.utils.BigDecimalUtils
import com.compass.mobile.framework.utils.DateUtils
import com.compass.mobile.models.IndependentBillingBean
import com.compass.mobile.models.OrderBean
import com.compass.mobile.models.PrescriptionRecord

/**
 * Description： 处方
 * Date:2024/6/19 14:36
 */
class PrescriptionPresenter : Presenter() {


    override fun onCreateViewHolder(viewGroup: ViewGroup): ViewHolder {
        val view =
            LayoutInflater.from(viewGroup.context)
                .inflate(R.layout.item_following, viewGroup, false)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(viewHolder: Presenter.ViewHolder, item: Any) {
        if (item is PrescriptionRecord) {
            val vh = viewHolder as ViewHolder
            vh.tvCreateTime.text =
                "开方日期：${DateUtils.conversionTime(item.createTime, DateUtils.FORMAT_TWO)}"
            vh.tvDepartmentName.text = "科室名称：${item.departmentName}"
            vh.tvDoctorName.text = "开方医生：${item.doctorName}"
            vh.tvDiagnosis.text = "临床诊断：${item.diagnosisStr}"
            vh.tvDrugs.text = "处方药品：${item.drugNameStr}"
            vh.tvPrice.text = "合计金额：￥${BigDecimalUtils.divide(item.price)}元"
            vh.tvStatusName.text=item.statusName

            when (item.status) {
                "4" -> {
                    vh.tvPay.gone()
                    if (item.continueStatus=="0"){
                        vh.tvSubmit.visible()
                    }else{
                        vh.tvSubmit.gone()
                    }

                }

                "1" -> {
                    vh.tvPay.visible()
                    vh.tvSubmit.gone()
                }

                else -> {
                    vh.tvSubmit.gone()
                    vh.tvPay.gone()
                }
            }

        }
    }

    override fun onUnbindViewHolder(viewHolder: Presenter.ViewHolder) {}
    class ViewHolder(view: View) : Presenter.ViewHolder(view) {
        var tvCreateTime: TextView = view.findViewById(R.id.tvCreateTime)
        var tvDiagnosis: TextView = view.findViewById(R.id.tvDiagnosis)
        var tvDrugs: TextView = view.findViewById(R.id.tvDrugs)
        var tvPrice: TextView = view.findViewById(R.id.tvPrice)
        var tvDoctorName: TextView = view.findViewById(R.id.tvDoctorName)
        var tvDepartmentName: TextView = view.findViewById(R.id.tvDepartmentName)

        var tvSubmit: TextView = view.findViewById(R.id.tvSubmit)
        var tvPay: TextView = view.findViewById(R.id.tvPay)
        var tvStatusName: TextView = view.findViewById(R.id.tvStatusName)
    }
}